#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <pthread.h>

void *th_func(void *arg)
{
    int specific = (int)(int *)arg;
    int i = 0;
    for (; i <= specific; ++i)
    {
        printf("%lx run %d m\n", pthread_self(), i);

        int time = (int)(drand48() * 10000);
        usleep(time);
    }

    return (void *)0;
}

int main()
{
    pthread_t rabbit, tortoise;

    if (pthread_create(&rabbit, NULL, th_func, (void *)100) != 0)
    {
        perror("pthread_create error!");
    }

    if (pthread_create(&tortoise, NULL, th_func, (void *)100) != 0)
    {
        perror("pthread_create error!");
    }

    pthread_join(rabbit, NULL);
    pthread_join(tortoise, NULL);

    printf("Main control pthread %lx exit!\n", pthread_self());
    return 0;
}